﻿// Example header text. Can be configured in the options.
using System;
using vtech_frameWorks.Exceptions;

namespace vtech_formBase
{
    public partial class frmAdd : Object.frmObject
    {
        #region "Delegate"
        protected virtual void FireEvent()
        {
        }

        #endregion

        public frmAdd()
        {
            this.InitializeComponent();
        }

        #region Close
        /// <summary>
        /// Đóng form
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnClose_Click(object sender, EventArgs e)
        {
            try
            {
                this.Close();
            }
            catch (Exception ex)
            {
                ClsInformation.Error(ex.Message);
            }
        }

        #endregion

        #region CheckControl
        /// <summary>
        /// Hàm kiểm tra các điều khiển
        /// </summary>
        /// <returns></returns>
        protected virtual Boolean CheckControl()
        {
            return true;
        }

        #endregion

        #region EditState
        /// <summary>
        /// Hàm xóa dữ liệu các control
        /// </summary>
        /// <returns></returns>
        protected virtual void EditState()
        {
        }

        #endregion

        #region Insert
        /// <summary>
        /// Thêm mới vào csdl
        /// </summary>
        protected virtual void Insert()
        {
        }

        /// <summary>
        /// Lưu dữ liệu và đóng form
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.CheckControl())
                {
                    this.Insert();
                    this.FireEvent();
                    this.Close();
                }
                else
                {
                    return;
                }
            }
            catch (Exception ex)
            {
                ClsInformation.Error(ex.Message);
            }
        }
        #endregion
    }
}